//
//  SPChatViewController.m
//  Sport
//
//  Created by Cass on 2018/4/7.
//  Copyright © 2018年 Cass. All rights reserved.
//

#import "SPChatViewController.h"
#import "SPMessageCell.h"
#import "SPMessage.h"
#import "SPMessageFrame.h"
@interface SPChatViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *messageFrames;

@end

@implementation SPChatViewController

- (NSMutableArray *)messageFrames{
    if (!_messageFrames) {
        
        NSMutableArray *arrayModels = [NSMutableArray array];
        SPMessage *model0 = [[SPMessage alloc]init];
        model0.text = @"今天天气很好";
        model0.time = @"09:23";
        model0.hideTime = NO;
        model0.type = 0;
        SPMessageFrame *modelFrame0 = [[SPMessageFrame alloc]init];
        modelFrame0.message = model0;
        [arrayModels addObject:modelFrame0];
        
        SPMessage *model1 = [[SPMessage alloc]init];
        model1.text = @"还不错";
        model1.time = @"10:23";
        model1.hideTime = NO;
        model1.type = 1;
        SPMessageFrame *modelFrame1 = [[SPMessageFrame alloc]init];
        modelFrame1.message = model1;
        [arrayModels addObject:modelFrame1];
        _messageFrames = arrayModels;
    }
    return _messageFrames;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

}

#pragma mark - UITableViewDataSource -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.messageFrames.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //获取模型数据
    SPMessageFrame *messageFrame = self.messageFrames[indexPath.row];
    //创建单元格
    SPMessageCell *cell = [SPMessageCell messageCellWithTableView:tableView];
    cell.messageFrame = messageFrame;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    SPMessageFrame *messageFrame = self.messageFrames[indexPath.row];
    return messageFrame.cellHeight;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
